package com.itheima.tliasmanager.controller;

import com.itheima.tliasmanager.annotation.Log;
import com.itheima.tliasmanager.pojo.domain.Dept;
import com.itheima.tliasmanager.pojo.Vo.Result;
import com.itheima.tliasmanager.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/depts")
@RestController
public class DeptController {

    @Autowired
    private DeptService deptService;

    @GetMapping
    public Result list() {
        log.info("查询全部部门,参数:无");
        List<Dept> depts = deptService.list();
        return Result.success(depts);
    }

    @Log
    @DeleteMapping
    public Result removeById(@RequestParam Integer id) {
        log.info("删除部门,参数: {}",id);
        deptService.removeByDeptId(id);
        return Result.success();
    }

    @Log
    @PostMapping
    public Result add(@RequestBody Dept dept) {
        log.info("新增部门,请求参数 = {}" ,dept);
        deptService.saveDept(dept);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id) {
        log.info("部门查询详情,id = {}" , id);
        Dept dept = deptService.getById( id);
        return Result.success(dept);
    }

    @Log
    @PutMapping
    public Result updata(@RequestBody Dept dept) {
        log.info("更新部门,请求参数: {}",dept);
        deptService.updateByDeptId(dept);
        return Result.success();
    }
}




















